/*
 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.lttng.scope.views.timeline.widgets.timegraph.layer;

import com.efficios.jabberwocky.common.TimeRange;
import com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender;
import javafx.scene.Group;
import org.jetbrains.annotations.Nullable;
import org.lttng.scope.views.timeline.widgets.timegraph.TimeGraphWidget;
import org.lttng.scope.views.timeline.widgets.timegraph.VerticalPosition;

import java.util.concurrent.FutureTask;

/**
 * Base class for layers of the timegraph, providing one particular data aspect.
 *
 * @author Alexandre Montplaisir
 */
public abstract class TimeGraphLayer {

    private final TimeGraphWidget fWidget;
    private final Group fParentGroup;

    /**
     * Constructor
     *
     * @param widget
     *            The widget to which this layer belongs
     * @param parentGroup
     *            The group to which this layer should add its children
     */
    public TimeGraphLayer(TimeGraphWidget widget, Group parentGroup) {
        fWidget = widget;
        fParentGroup = parentGroup;
    }

    /**
     * Get the layer's widget.
     *
     * @return The widget
     */
    protected TimeGraphWidget getWidget() {
        return fWidget;
    }

    /**
     * Get this layer's parent group, in which all its generated children should
     * be added.
     *
     * @return The parent group
     */
    public Group getParentGroup() {
        return fParentGroup;
    }

    /**
     * Ask the layer to populate its scenegraph. This is usually done by having
     * the Layer add children Nodes to itself.
     *
     * @param treeRender
     *            The current tree render of the time graph. Can be used to get
     *            the number of visible entries, etc.
     * @param timeRange
     *            The time range, or "horizontal position" of the current
     *            visible window
     * @param vPos
     *            The vertical position of the current visible window
     * @param task
     *            An optional Task which is calling this method. Long-running
     *            implementations are encouraged to check the 'cancelled' status
     *            of this Task periodically (if supplied), and early exit in
     *            case of cancellation.
     */
    public abstract void drawContents(TimeGraphTreeRender treeRender, TimeRange timeRange,
            VerticalPosition vPos, @Nullable FutureTask<?> task);

    /**
     * Remove from the scenegraph the Nodes generated by this layer.
     */
    public abstract void clear();
}
